package com.zxjbyte.yiyi.module.upms.convert;

import cn.hutool.core.util.StrUtil;
import com.zxjbyte.yiyi.module.upms.domain.entity.UserPO;
import com.zxjbyte.yiyi.module.upms.domain.param.UserAddParam;
import com.zxjbyte.yiyi.module.upms.domain.param.UserUpdateParam;
import com.zxjbyte.yiyi.module.upms.domain.vo.UserDetailVO;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;

/**
 * @Author zhangxingjia
 * @Date 2024/12/27 17:04
 * @Version: 1.0
 */
@Mapper(componentModel = "spring")
public interface UserConvert {

    UserConvert INSTANCE = Mappers.getMapper(UserConvert.class);

    UserPO addParamToPo(UserAddParam addParam);

    UserDetailVO poToDetailVo(UserPO po);

    default void updatePoFromParam(UserPO userPo, UserUpdateParam updateParam){
        userPo.setAccount(updateParam.getAccount());
        userPo.setRealName(updateParam.getRealName());
        userPo.setGender(updateParam.getGender());
        userPo.setBirthday(updateParam.getBirthday());
        userPo.setAvatar(updateParam.getAvatar());
        userPo.setPhone(updateParam.getPhone());
        userPo.setIdType(updateParam.getIdType());
        userPo.setStatus(updateParam.getStatus());
        userPo.setNickName(StrUtil.nullToEmpty(userPo.getNickName()));
        userPo.setRemark(StrUtil.nullToEmpty(userPo.getRemark()));
        userPo.setEmail(StrUtil.nullToEmpty(userPo.getEmail()));
        userPo.setIdNo(StrUtil.nullToEmpty(userPo.getIdNo()));
    }
}
